﻿''' <summary>
''' Provides a collection of Sprites keyed by name which can be sorted by z-order.
''' </summary>
''' <remarks></remarks>
Public Class SpriteCollection
    Inherits System.Collections.ObjectModel.KeyedCollection(Of String, Sprite)

    Protected Overrides Function GetKeyForItem(ByVal item As Sprite) As String
        Return item.Name
    End Function

    ''' <summary>
    ''' Returns the contents of the collection as an array of Sprites sorted by their z-order value.
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function ToZOrderedArray() As Sprite()
        If Count > 0 Then
            Dim result(Count - 1) As Sprite
            CopyTo(result, 0)
            Array.Sort(result, Function(source As Sprite, other As Sprite) source.ZOrder.CompareTo(other.ZOrder))
            Return result
        End If
        Return New Sprite() {}
    End Function
End Class
